<?php 
/* 
 *************************************************************************
 *                                                                       *
 * Product: Płatności.pl for OpenCart 	    		           			 *
 * Release Date: 21.02.2011                                              *
 * Author: Daniel Miara                                  	             *
 * Version: 1.4.9.3                                                      *
 * For: OpenCart 					                                     *
 *                                                                       *
 * Author: 3D Studio Production                                          *
 * Email: daniel@3dstudiopro.com           			                     *
 * Website: www.3dstudiopro.com              			                 *
 * Copyright: (C) 2001-2011 All rights reserved.                         *
 * Licence: Commercial                                                   *
 *                                                                       *
 *************************************************************************
 *                                                                       *
 * This software is furnished under a license and may be used and copied *
 * only  in  accordance  with  the  terms  of such  license and with the *
 * inclusion of the above copyright notice.  This software  or any other *
 * copies thereof may not be provided or otherwise made available to any *
 * other person.  No title to and  ownership of the  software is  hereby *
 * transferred.                                                          *
 *                                                                       *
 * You may not reverse  engineer, decompile, defeat license  encryption  *
 * mechanisms, or disassemble this software product or software product  *
 * license.  3D Studio Production  may  terminate  this license  if you  *
 * fail to comply with any of the terms and conditions set forth in our  *
 * end user license agreement (EULA).  									 *
 *                                                                       *
 *                                                                       *
 * To oprogramowanie jest dostarczane w ramach licencji i może być	 	 *
 * używane i kopiowane tylko zgodnie z warunkami licencji i z 			 *
 * uwzględnieniem powyższych praw autorskich. Oprogramowania lub jego 	 * 
 * kopia nie może być przekazywana udostępnione innym trzecim.		 	 *
 *                                                                       *
 * Nie można modyfikować, dekompilować, łamać mechanizmy szyfrowania 	 *
 * tego oprogramowania lub kasować informacji o licencji oprogramowania. * 
 * 3D Studio Production może wypowiedzieć niniejszą licencję, jeśli nie  * 
 * są spełnione którekolwiek z warunków określonych w naszej umowie  	 *
 * licencyjnej użytkownika końcowego (EULA). 							 *
 *                                                                       *
 *************************************************************************
*/
class ControllerPaymentPlatnosci extends Controller {
	private $error = array(); 

	public function index() {
		$this->load->language('payment/platnosci');

		$this->document->title = $this->language->get('heading_title');
		
		$this->load->model('setting/setting');
			
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
			$this->load->model('setting/setting');
			
			$this->model_setting_setting->editSetting('platnosci', $this->request->post);				
			
			$this->session->data['success'] = $this->language->get('text_success');

			$this->redirect(HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token']);
		}

		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_all_zones'] = $this->language->get('text_all_zones');
		$this->data['text_yes'] = $this->language->get('text_yes');
		$this->data['text_no'] = $this->language->get('text_no');
		$this->data['text_authorization'] = $this->language->get('text_authorization');
		$this->data['text_sale'] = $this->language->get('text_sale');
		
		// fields
		$this->data['entry_numer'] = $this->language->get('entry_numer');
		$this->data['entry_pin'] = $this->language->get('entry_pin');
		$this->data['entry_lang'] = $this->language->get('entry_lang');
		$this->data['entry_test'] = $this->language->get('entry_test');
		$this->data['entry_transaction'] = $this->language->get('entry_transaction');
		$this->data['entry_order_status'] = $this->language->get('entry_order_status');	
		$this->data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');

		$this->data['tab_general'] = $this->language->get('tab_general');
		$this->data['error_required'] = $this->language->get('error_required');
		
		//$this->data['a'] = $this->config->get('config_email');
		
		// warrnins
 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
		$this->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token'],
       		'text'      => $this->language->get('text_payment'),
      		'separator' => ' :: '
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTPS_SERVER . 'index.php?route=payment/platnosci&token=' . $this->session->data['token'],
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);
				
		$this->data['action'] = HTTPS_SERVER . 'index.php?route=payment/platnosci&token=' . $this->session->data['token'];
		
		$this->data['cancel'] = HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token'];
		
		if (isset($this->request->post['platnosci_id'])) {
			$this->data['platnosci_id'] = $this->request->post['platnosci_id'];
		} else {
			$this->data['platnosci_id'] = $this->config->get('platnosci_id');
		}
		if (isset($this->request->post['platnosci_auth_key'])) {
			$this->data['platnosci_auth_key'] = $this->request->post['platnosci_auth_key'];
		} else {
			$this->data['platnosci_auth_key'] = $this->config->get('platnosci_auth_key');
		}
				
		if (isset($this->request->post['platnosci_potwierdzenie'])) {
			$this->data['platnosci_potwierdzenie'] = $this->request->post['platnosci_potwierdzenie'];
		} else {
			$this->data['platnosci_potwierdzenie'] = $this->config->get('platnosci_potwierdzenie');
		}
		
		if (isset($this->request->post['platnosci_key_one'])) {
			$this->data['platnosci_key_one'] = $this->request->post['platnosci_key_one'];
		} else {
			$this->data['platnosci_key_one'] = $this->config->get('platnosci_key_one');
		}
		
		if (isset($this->request->post['platnosci_key_two'])) {
			$this->data['platnosci_key_two'] = $this->request->post['platnosci_key_two'];
		} else {
			$this->data['platnosci_key_two'] = $this->config->get('platnosci_key_two');
		}
		
		if (isset($this->request->post['platnosci_rows'])) {
			$this->data['platnosci_rows'] = $this->request->post['platnosci_rows'];
		} else {
			$this->data['platnosci_rows'] = $this->config->get('platnosci_rows');
		}
		
		if (isset($this->request->post['platnosci_button'])) {
			$this->data['platnosci_button'] = $this->request->post['platnosci_button'];
		} else {
			$this->data['platnosci_button'] = $this->config->get('platnosci_button');
		}
		
		if (isset($this->request->post['platnosci_css'])) {
			$this->data['platnosci_css'] = $this->request->post['platnosci_css'];
		} else {
			$this->data['platnosci_css'] = $this->config->get('platnosci_css');
		}
		
		
		if (isset($this->request->post['platnosci_option'])) {
			$this->data['platnosci_option'] = $this->request->post['platnosci_option'];
		} else {
			$this->data['platnosci_option'] = $this->config->get('platnosci_option');
		}
		
		if (isset($this->request->post['platnosci_onlinetransfer'])) {
			$this->data['platnosci_onlinetransfer'] = $this->request->post['platnosci_onlinetransfer'];
		} else {
			$this->data['platnosci_onlinetransfer'] = $this->config->get('platnosci_onlinetransfer');
		}

		if (isset($this->request->post['platnosci_transaction'])) {
			$this->data['platnosci_transaction'] = $this->request->post['platnosci_transaction'];
		} else {
			$this->data['platnosci_transaction'] = $this->config->get('platnosci_transaction');
		}
		
		if (isset($this->request->post['platnosci_order_zrealizowana'])) {
			$this->data['platnosci_order_zrealizowana'] = $this->request->post['platnosci_order_zrealizowana'];
		} else {
			$this->data['platnosci_order_zrealizowana'] = $this->config->get('platnosci_order_zrealizowana'); 
		} 
		
		if (isset($this->request->post['platnosci_order_nowa'])) {
			$this->data['platnosci_order_nowa'] = $this->request->post['platnosci_order_nowa'];
		} else {
			$this->data['platnosci_order_nowa'] = $this->config->get('platnosci_order_nowa');
		}
		
		if (isset($this->request->post['platnosci_order_odmowna'])) {
			$this->data['platnosci_order_odmowna'] = $this->request->post['platnosci_order_odmowna'];
		} else {
			$this->data['platnosci_order_odmowna'] = $this->config->get('platnosci_order_odmowna');
		}
		
		if (isset($this->request->post['platnosci_order_anulowana'])) {
			$this->data['platnosci_order_anulowana'] = $this->request->post['platnosci_order_anulowana'];
		} else {
			$this->data['platnosci_order_anulowana'] = $this->config->get('platnosci_order_anulowana');
		}
		if (isset($this->request->post['regPl'])) {
			$this->data['regPl'] = $this->request->post['regPl'];
		} else {
			$this->data['regPl'] = $this->config->get('regPl');
		}



		$this->load->model('localisation/order_status');
		
		$this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
		
		if (isset($this->request->post['platnosci_geo_zone_id'])) {
			$this->data['platnosci_geo_zone_id'] = $this->request->post['platnosci_geo_zone_id'];
		} else {
			$this->data['platnosci_geo_zone_id'] = $this->config->get('platnosci_geo_zone_id'); 
		} 
		
		$this->load->model('localisation/geo_zone');
										
		$this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
		
		if (isset($this->request->post['platnosci_status'])) {
			$this->data['platnosci_status'] = $this->request->post['platnosci_status'];
		} else {
			$this->data['platnosci_status'] = $this->config->get('platnosci_status');
		}
		
		if (isset($this->request->post['platnosci_sort_order'])) {
			$this->data['platnosci_sort_order'] = $this->request->post['platnosci_sort_order'];
		} else {
			$this->data['platnosci_sort_order'] = $this->config->get('platnosci_sort_order');
		}
		
		$this->template = 'payment/platnosci.tpl';
		$this->children = array(
			'common/header',	
			'common/footer'	,
			'common/platnosci'
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
	// validate
	private function validate() {
		if (!$this->user->hasPermission('modify', 'payment/platnosci')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		
		if (!$this->request->post['platnosci_id']) {
			$this->error['platnosci_id'] = $this->language->get('error_numer');
		}
		if (!$this->request->post['platnosci_auth_key']) {
			$this->error['platnosci_auth_key'] = $this->language->get('error_numer');
		}
		if (!$this->request->post['platnosci_key_two']) {
			$this->error['platnosci_key_two'] = $this->language->get('error_numer');
		}
		if (!$this->request->post['platnosci_key_one']) {
			$this->error['platnosci_key_one'] = $this->language->get('error_numer');
		}
		
		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}	
	}
}
?>